const loginModule = {
    login() {
        const username = document.getElementById('login-username').value;
        const password = document.getElementById('login-password').value;

        if (!username || !password) {
            alert('请输入用户名和密码！');
            return;
        }

        const user = dataModule.validateUser(username, password);
        if (user) {
            // 将用户信息存储在 sessionStorage 中
            sessionStorage.setItem('currentUser', username);
            window.location.href = 'main.html';
        } else {
            alert('用户名或密码错误！');
        }
    }
};

// 检查是否已登录
document.addEventListener('DOMContentLoaded', () => {
    if (sessionStorage.getItem('currentUser')) {
        window.location.href = 'main.html';
    }

    document.addEventListener('keypress', (e) => {
        if (e.key === 'Enter') {
            loginModule.login();
        }
    });
}); 